package com.five.wisdomEat.service;

import com.five.wisdomEat.entity.Comment;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentService {
    @Autowired
    private CommentMapper mapper;
    public ResponseMessage selectCommentList(){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectCommentList());
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage insertComment(Comment comment){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.insertComment(comment)>0?true:false;
        if(flag){
            message.setMessage("添加成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("添加失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage updateComment(Comment comment){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.updateComment(comment)>0?true:false;
        if(flag){
            message.setMessage("更新成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("更新失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage deleteComment(Integer id){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.deleteComment(id)>0?true:false;
        if(flag){
            message.setMessage("删除成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("删除失败");
            message.setSuccess(flag);
        }
        return message;
    }
}
